package cn.songhaiqing.walle.help;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;

import cn.songhaiqing.walle.bean.HeartDaily;
import cn.songhaiqing.walle.bean.HistoryDay;
import cn.songhaiqing.walle.bean.HistoryHour;
import cn.songhaiqing.walle.bean.HistoryMonth;
import cn.songhaiqing.walle.bean.SensorHour;
import cn.songhaiqing.walle.ble.constant.Constants;
import cn.songhaiqing.walle.bledemo.R;

public class CalendarHelper {
    public static Calendar get20010101Datetime() {
        Calendar cal_ = Calendar.getInstance();
        cal_.set(1, 2000);
        cal_.set(2, 0);
        cal_.set(5, 1);
        cal_.set(11, 0);
        cal_.set(12, 0);
        cal_.set(13, 0);
        cal_.set(14, 0);
        return cal_;
    }

    public static Calendar setDayFormat(Calendar cal) {
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static void setCalendarColor(View view, Calendar calendar) {
        switch (calendar.get(2)) {
          /*  case 0:
                view.setBackgroundResource(R.drawable.image_calendar_1);
                return;
            case 1:
                view.setBackgroundResource(R.drawable.image_calendar_2);
                return;
            case 2:
                view.setBackgroundResource(R.drawable.image_calendar_3);
                return;
            case 3:
                view.setBackgroundResource(R.drawable.image_calendar_4);
                return;
            case 4:
                view.setBackgroundResource(R.drawable.image_calendar_5);
                return;
            case 5:
                view.setBackgroundResource(R.drawable.image_calendar_6);
                return;
            case 6:
                view.setBackgroundResource(R.drawable.image_calendar_7);
                return;
            case 7:
                view.setBackgroundResource(R.drawable.image_calendar_8);
                return;
            case 8:
                view.setBackgroundResource(R.drawable.image_calendar_9);
                return;
            case 9:
                view.setBackgroundResource(R.drawable.image_calendar_10);
                return;
            case 10:
                view.setBackgroundResource(R.drawable.image_calendar_11);
                return;
            case 11:
                view.setBackgroundResource(R.drawable.image_calendar_12);
                return;*/
            default:
                return;
        }
    }

    public static Calendar setHourFormat(Calendar cal) {
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static Calendar setMinuteFormat(Calendar cal) {
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static Calendar setMonthFormat(Calendar cal) {
        cal.set(5, 1);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static Calendar getToday() {
        Calendar cal = Calendar.getInstance();
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static Calendar getYesterday(Calendar cal) {
        Calendar temp = Calendar.getInstance();
        temp.setTimeInMillis(cal.getTimeInMillis());
        return minADay(temp);
    }

    public static Calendar getDateBeforeYesterday(Calendar cal) {
        Calendar temp = Calendar.getInstance();
        temp.setTimeInMillis(cal.getTimeInMillis());
        return minADay(minADay(temp));
    }

    public static Calendar addADay(Calendar cal) {
        cal.set(5, cal.get(5) + 1);
        return cal;
    }

    public static Calendar minAYear(Calendar cal) {
        cal.set(1, cal.get(1) - 1);
        cal.set(2, 0);
        cal.set(6, 1);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static Calendar minADay(Calendar cal) {
        cal.set(5, cal.get(5) - 1);
        return cal;
    }

    public static Calendar addAnHour(Calendar cal) {
        cal.set(11, cal.get(11) + 1);
        return cal;
    }

    public static Calendar addAMonth(Calendar cal) {
        cal.set(2, cal.get(2) + 1);
        cal.set(5, 1);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal;
    }

    public static String getMonthStr(Context context, int month) {
       /* if (month == 0) {
            return context.getString(R.string.Month_JAN);
        }
        if (month == 1) {
            return context.getString(R.string.Month_FEB);
        }
        if (month == 2) {
            return context.getString(R.string.Month_MAR);
        }
        if (month == 3) {
            return context.getString(R.string.Month_APR);
        }
        if (month == 4) {
            return context.getString(R.string.Month_MAY);
        }
        if (month == 5) {
            return context.getString(R.string.Month_JUN);
        }
        if (month == 6) {
            return context.getString(R.string.Month_JUL);
        }
        if (month == 7) {
            return context.getString(R.string.Month_AUG);
        }
        if (month == 8) {
            return context.getString(R.string.Month_SEP);
        }
        if (month == 9) {
            return context.getString(R.string.Month_OCT);
        }
        if (month == 10) {
            return context.getString(R.string.Month_NOV);
        }
        if (month == 11) {
            return context.getString(R.string.Month_DEC);
        }*/
        return null;
    }

    public static String getDayOfWeekStr(Context context, int dayOfWeek) {
    /*    if (dayOfWeek == 2) {
            return context.getString(R.string.Week_MON);
        }
        if (dayOfWeek == 3) {
            return context.getString(R.string.Week_TUE);
        }
        if (dayOfWeek == 4) {
            return context.getString(R.string.Week_WED);
        }
        if (dayOfWeek == 5) {
            return context.getString(R.string.Week_THU);
        }
        if (dayOfWeek == 6) {
            return context.getString(R.string.Week_FRI);
        }
        if (dayOfWeek == 7) {
            return context.getString(R.string.Week_SAT);
        }
        if (dayOfWeek == 1) {
            return context.getString(R.string.Week_SUN);
        }*/
        return null;
    }

    public static void setDateInformation(Context context, Calendar cal, TextView text_date, TextView button_date_right) {
        int day = cal.get(5);
        int month = cal.get(2);
        int dayOfWeek = cal.get(7);
        if (cal.equals(getToday())) {
            //   button_date_right.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(R.drawable.button_home_right_arrow_close), (Drawable) null, (Drawable) null, (Drawable) null);
        } else {
//            button_date_right.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(R.drawable.button_home_right_arrow), (Drawable) null, (Drawable) null, (Drawable) null);
        }
        String dayOfWeekStr = getDayOfWeekStr(context, dayOfWeek);
        String monthStr = getMonthStr(context, month);
        if (dayOfWeekStr != null && monthStr != null) {
            Log.i("testheart", "*********** lan");
            String language = Locale.getDefault().getLanguage();
            Log.i("testheart", "*********** lan ok");
            if (language.equals("zh")) {
                //    text_date.setText(dayOfWeekStr + "  " + monthStr + FormatHelper.df_0.format((long) day) + context.getString(R.string.Movement_DAY));
                return;
            }
            String dayOfWeekStr2 = dayOfWeekStr.toLowerCase();
            String monthStr2 = monthStr.toLowerCase();
            text_date.setText(dayOfWeekStr2.substring(0, 1).toUpperCase() + dayOfWeekStr2.substring(1) + " " + FormatHelper.df_00.format((long) day) + " " + monthStr2.substring(0, 1).toUpperCase() + monthStr2.substring(1));
        }
    }

    public static void setDateInformation(Context context, Calendar cal, TextView text_date, TextView button_date_right, TextView text_date_time_edit) {
        int day = cal.get(5);
        int month = cal.get(2);
        int dayOfWeek = cal.get(7);
        if (cal.equals(getToday())) {
            //  button_date_right.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(R.drawable.button_home_right_arrow_close), (Drawable) null, (Drawable) null, (Drawable) null);
            text_date_time_edit.setVisibility(View.VISIBLE);
        } else {
            //   button_date_right.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(R.drawable.button_home_right_arrow), (Drawable) null, (Drawable) null, (Drawable) null);
            text_date_time_edit.setVisibility(View.GONE);
        }
        String dayOfWeekStr = getDayOfWeekStr(context, dayOfWeek);
        String monthStr = getMonthStr(context, month);
        if (dayOfWeekStr != null && monthStr != null) {
            Log.i("testheart", "*********** lan");
            String language = Locale.getDefault().getLanguage();
            Log.i("testheart", "*********** lan ok");
            if (language.equals("zh")) {
              //  text_date.setText(dayOfWeekStr + "  " + monthStr + FormatHelper.df_0.format((long) day) + context.getString(R.string.Movement_DAY));
                return;
            }
            String dayOfWeekStr2 = dayOfWeekStr.toLowerCase();
            String monthStr2 = monthStr.toLowerCase();
            text_date.setText(dayOfWeekStr2.substring(0, 1).toUpperCase() + dayOfWeekStr2.substring(1) + " " + FormatHelper.df_00.format((long) day) + " " + monthStr2.substring(0, 1).toUpperCase() + monthStr2.substring(1));
        }
    }

    public static Calendar[] getYesterdayToTomorrow(Calendar today) {
        Calendar yesterday = Calendar.getInstance();
        yesterday.setTimeInMillis(today.getTimeInMillis());
        Calendar yesterday2 = setDayFormat(minADay(yesterday));
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return new Calendar[]{yesterday2, setDayFormat(addADay(tomorrow))};
    }

    public static Calendar[] getTodayToTomorrow(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today2.getTimeInMillis());
        return new Calendar[]{today2, setDayFormat(addADay(tomorrow))};
    }

    public static Calendar[] getSleepTime(Context context, int profileID, Calendar today) {
        Calendar cal_today = Calendar.getInstance();
        cal_today.setTimeInMillis(today.getTimeInMillis());
        addADay(cal_today);
        Calendar cal_yestoday = Calendar.getInstance();
        cal_yestoday.setTimeInMillis(today.getTimeInMillis());
        minADay(cal_yestoday);
        return new Calendar[]{cal_yestoday, cal_today};
    }

    public static Calendar[] getSleepTime(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar cal_today = Calendar.getInstance();
        cal_today.setTimeInMillis(today2.getTimeInMillis());
        addADay(cal_today);
        Calendar cal_yestoday = Calendar.getInstance();
        cal_yestoday.setTimeInMillis(today2.getTimeInMillis());
        minADay(cal_yestoday);
        return new Calendar[]{cal_yestoday, cal_today};
    }

    public static Calendar[] getByDays(Calendar today, int days) {
        Calendar today2 = setDayFormat(today);
        Calendar cal_today = Calendar.getInstance();
        cal_today.setTimeInMillis(today2.getTimeInMillis());
        addADay(cal_today);
        Calendar cal_day = Calendar.getInstance();
        cal_day.setTimeInMillis(today2.getTimeInMillis());
        cal_day.set(5, cal_day.get(5) - days);
        return new Calendar[]{cal_day, cal_today};
    }

    public static Calendar[] getByMonths(Calendar today, int months) {
        Calendar today2 = setDayFormat(today);
        Calendar cal_today = Calendar.getInstance();
        cal_today.setTimeInMillis(today2.getTimeInMillis());
        cal_today.set(2, cal_today.get(2) + 1);
        cal_today.set(5, 1);
        cal_today.set(11, 0);
        cal_today.set(12, 0);
        cal_today.set(13, 0);
        cal_today.set(14, 0);
        Calendar cal_month = Calendar.getInstance();
        cal_month.setTimeInMillis(today2.getTimeInMillis());
        cal_month.set(2, cal_month.get(2) - months);
        cal_month.set(5, 1);
        cal_month.set(11, 0);
        cal_month.set(12, 0);
        cal_month.set(13, 0);
        cal_month.set(14, 0);
        return new Calendar[]{cal_month, cal_today};
    }

    public static Calendar[] getTwoYearsTime(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar cal_today = Calendar.getInstance();
        cal_today.setTimeInMillis(today2.getTimeInMillis());
        addADay(cal_today);
        Calendar cal_lastYear = Calendar.getInstance();
        cal_lastYear.setTimeInMillis(today2.getTimeInMillis());
        minAYear(cal_lastYear);
        return new Calendar[]{cal_lastYear, cal_today};
    }

    public static Calendar getWeekCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(7, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getLastWeekCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(4, calendar.get(4) - 1);
        calendar.set(7, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getMonthCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getLastMonthCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(2, calendar.get(2) - 1);
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static int getLastMonthDays(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        calendar.set(5, calendar.get(5) - 1);
        return calendar.get(5);
    }

    public static int getLastYearDays(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(6, 1);
        calendar.set(5, calendar.get(5) - 1);
        return calendar.get(6);
    }

    public static Calendar getQuarterCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(2, today.get(2) - (today.get(2) % 3));
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getLastQuarterCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(2, (today.get(2) - (today.get(2) % 3)) - 3);
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getYearCalendar(Calendar today) {
        Calendar today2 = setDayFormat(today);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(today2.getTimeInMillis());
        calendar.set(2, 0);
        calendar.set(5, 1);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar;
    }

    public static Calendar getTomorrow(Calendar today) {
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return setDayFormat(addADay(tomorrow));
    }

    public static Calendar[] getLastWeekToTomorrow(Calendar today) {
        Calendar lastWeek = Calendar.getInstance();
        lastWeek.setTimeInMillis(today.getTimeInMillis());
        lastWeek.set(5, lastWeek.get(5) - 7);
        Calendar lastWeek2 = setDayFormat(lastWeek);
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return new Calendar[]{lastWeek2, setDayFormat(addADay(tomorrow))};
    }

    public static Calendar[] getLastMonthToTomorrow(Calendar today) {
        Calendar lastMonth = Calendar.getInstance();
        lastMonth.setTimeInMillis(today.getTimeInMillis());
        lastMonth.set(5, lastMonth.get(5) - 30);
        Calendar lastMonth2 = setDayFormat(lastMonth);
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return new Calendar[]{lastMonth2, setDayFormat(addADay(tomorrow))};
    }

    public static Calendar[] getLastMonthToTomorrowSleep(Calendar today) {
        Calendar lastMonth = Calendar.getInstance();
        lastMonth.setTimeInMillis(today.getTimeInMillis());
        lastMonth.set(5, lastMonth.get(5) - 30);
        Calendar lastMonth2 = setDayFormat(lastMonth);
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return new Calendar[]{lastMonth2, setDayFormat(addADay(tomorrow))};
    }

    public static Calendar[] getLastYearToTomorrow(Calendar today) {
        Calendar lastYear = Calendar.getInstance();
        lastYear.setTimeInMillis(today.getTimeInMillis());
        lastYear.set(1, lastYear.get(1) - 1);
        Calendar lastYear2 = setDayFormat(lastYear);
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.setTimeInMillis(today.getTimeInMillis());
        return new Calendar[]{lastYear2, setDayFormat(addADay(tomorrow))};
    }

    public static Map<Calendar, HistoryMonth> getYearMap(Calendar today) {
        Map<Calendar, HistoryMonth> map = new LinkedHashMap<>();
        if (today != null) {
            for (int i = 11; i > -1; i--) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(today.getTimeInMillis());
                cal.set(2, cal.get(2) - i);
                map.put(setMonthFormat(cal), null);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryDay> getDayMap(Calendar[] calArray) {
        Map<Calendar, HistoryDay> map = new LinkedHashMap<>();
        if (calArray != null && calArray.length == 2) {
            Calendar begin = calArray[0];
            Calendar end = calArray[1];
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(begin.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(addADay(temp).getTimeInMillis());
                if (cal.equals(end)) {
                    break;
                }
                map.put(cal, null);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryDay> getDayMapSleep(Calendar[] calArray) {
        Map<Calendar, HistoryDay> map = new LinkedHashMap<>();
        if (calArray != null && calArray.length == 2) {
            Calendar begin = calArray[0];
            Calendar end = calArray[1];
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(begin.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(addADay(temp).getTimeInMillis());
                if (cal.equals(end)) {
                    break;
                }
                map.put(cal, null);
            }
        }
        return map;
    }

    public static Map<Calendar, HeartDaily> getDayMap_heart(Calendar[] calArray) {
        Map<Calendar, HeartDaily> map = new LinkedHashMap<>();
        if (calArray != null && calArray.length == 2) {
            Calendar begin = calArray[0];
            Calendar end = calArray[1];
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(begin.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(addADay(temp).getTimeInMillis());
                if (cal.equals(end)) {
                    break;
                }
                map.put(cal, null);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryHour> getHourMap(Calendar today) {
        Map<Calendar, HistoryHour> map = new LinkedHashMap<>();
        if (today != null) {
            map.put(today, null);
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(today.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(addAnHour(temp).getTimeInMillis());
                Calendar cal2 = setHourFormat(cal);
                if (cal2.get(5) != today.get(5)) {
                    break;
                }
                map.put(cal2, null);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryHour> getHourMap_sleep(final Activity context, int profileID, Calendar today, final TextView text_date_time_end, final TextView text_date_time_begin) {
        Calendar yesterday = Calendar.getInstance();
        yesterday.setTimeInMillis(today.getTimeInMillis());
        Calendar yesterday2 = minADay(yesterday);
        SleepHelper.getDayTime(context, profileID, today);
        Map<Calendar, HistoryHour> map = new LinkedHashMap<>();
        context.runOnUiThread(new Runnable() {
            /* class com.gzgamut.smart_movement.helper.CalendarHelper.AnonymousClass1 */

            public void run() {
                boolean is24 = DateFormat.is24HourFormat(context);
                String[] ARRAY_HOUR_BEGIN = new String[24];
                if (!is24) {
                    for (int i = 0; i < ARRAY_HOUR_BEGIN.length / 2; i++) {
                        ARRAY_HOUR_BEGIN[i] = FormatHelper.df_00.format((long) i);
                        ARRAY_HOUR_BEGIN[(ARRAY_HOUR_BEGIN.length / 2) + i] = FormatHelper.df_00.format((long) i);
                    }
                //    ARRAY_HOUR_BEGIN[0] = Constants.VIA_REPORT_TYPE_SET_AVATAR;
               //     ARRAY_HOUR_BEGIN[12] = Constants.VIA_REPORT_TYPE_SET_AVATAR;
                } else {
                    for (int i2 = 0; i2 < ARRAY_HOUR_BEGIN.length; i2++) {
                        ARRAY_HOUR_BEGIN[i2] = FormatHelper.df_00.format((long) i2);
                    }
                }
                String[] ARRAY_HOUR_END = new String[24];
                if (!is24) {
                    for (int i3 = 0; i3 < ARRAY_HOUR_END.length / 2; i3++) {
                        ARRAY_HOUR_END[i3] = FormatHelper.df_00.format((long) (i3 + 1));
                        ARRAY_HOUR_END[(ARRAY_HOUR_END.length / 2) + i3] = FormatHelper.df_00.format((long) (i3 + 1));
                    }
                } else {
                    for (int i4 = 0; i4 < ARRAY_HOUR_END.length; i4++) {
                        ARRAY_HOUR_END[i4] = FormatHelper.df_00.format((long) (i4 + 1));
                    }
                }
                if (!is24) {
                    // text_date_time_end.setText(ARRAY_HOUR_BEGIN[22] + ":00" + context.getString(R.string.Movement_PM));
                   // text_date_time_begin.setText(ARRAY_HOUR_END[23] + ":00" + context.getString(R.string.Movement_PM));
                    return;
                }
                text_date_time_end.setText("22:00");
                text_date_time_begin.setText("24:00");
            }
        });
        if (today != null) {
            Calendar yesterday_temp = Calendar.getInstance();
            yesterday_temp.setTimeInMillis(today.getTimeInMillis());
            Calendar yesterday_temp2 = minADay(yesterday_temp);
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(yesterday_temp2.getTimeInMillis());
                Calendar cal2 = setHourFormat(cal);
                if (cal2.get(5) != yesterday2.get(5)) {
                    break;
                }
                if (Integer.parseInt(FormatHelper.sdf_HH.format(cal2.getTime())) >= 22) {
                    map.put(cal2, null);
                }
                addAnHour(yesterday_temp2);
            }
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(today.getTimeInMillis());
            while (true) {
                Calendar cal3 = Calendar.getInstance();
                cal3.setTimeInMillis(temp.getTimeInMillis());
                Calendar cal4 = setHourFormat(cal3);
                if (cal4.get(5) != today.get(5)) {
                    break;
                }
                if (Integer.parseInt(FormatHelper.sdf_HH.format(cal4.getTime())) <= 23) {
                    map.put(cal4, null);
                }
                addAnHour(temp);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryHour> getHourMap_sleep(Calendar today) {
        Calendar yesterday = Calendar.getInstance();
        yesterday.setTimeInMillis(today.getTimeInMillis());
        Calendar yesterday2 = minADay(yesterday);
        Map<Calendar, HistoryHour> map = new LinkedHashMap<>();
        if (today != null) {
            Calendar yesterday_temp = Calendar.getInstance();
            yesterday_temp.setTimeInMillis(today.getTimeInMillis());
            Calendar yesterday_temp2 = minADay(yesterday_temp);
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(yesterday_temp2.getTimeInMillis());
                Calendar cal2 = setHourFormat(cal);
                if (cal2.get(5) != yesterday2.get(5)) {
                    break;
                }
                if (Integer.parseInt(FormatHelper.sdf_HH.format(cal2.getTime())) >= 22) {
                    map.put(cal2, null);
                }
                addAnHour(yesterday_temp2);
            }
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(today.getTimeInMillis());
            while (true) {
                Calendar cal3 = Calendar.getInstance();
                cal3.setTimeInMillis(temp.getTimeInMillis());
                Calendar cal4 = setHourFormat(cal3);
                if (cal4.get(5) != today.get(5)) {
                    break;
                }
                if (Integer.parseInt(FormatHelper.sdf_HH.format(cal4.getTime())) <= 23) {
                    map.put(cal4, null);
                }
                addAnHour(temp);
            }
        }
        return map;
    }

    public static Map<Calendar, HistoryHour> getHourMap_activity(Context context, Calendar today) {
        //SleepHelper.getDayTime(context, MainActivity.initProfileID(context), today);
        Map<Calendar, HistoryHour> map = new LinkedHashMap<>();
        if (today != null) {
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(today.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(temp.getTimeInMillis());
                Calendar cal2 = setHourFormat(cal);
                if (cal2.get(5) != today.get(5)) {
                    break;
                }
                int hourTemp = Integer.parseInt(FormatHelper.sdf_HH.format(cal2.getTime()));
                Log.i("changeSync", "hourTemp:" + hourTemp);
                if (hourTemp >= 0 && hourTemp < 24) {
                    map.put(cal2, null);
                }
                addAnHour(temp);
            }
        }
        return map;
    }

    public static Map<Calendar, SensorHour> getHourMap_sensor(Calendar today) {
        Map<Calendar, SensorHour> map = new LinkedHashMap<>();
        if (today != null) {
            map.put(today, null);
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(today.getTimeInMillis());
            while (true) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(addAnHour(temp).getTimeInMillis());
                Calendar cal2 = setHourFormat(cal);
                if (cal2.get(5) != today.get(5)) {
                    break;
                }
                map.put(cal2, null);
            }
        }
        return map;
    }

    public static boolean isDate1AfterDate2(Calendar date1, Calendar date2) {
        if (setDayFormat(date1).after(setDayFormat(date2))) {
            return true;
        }
        return false;
    }

    public static boolean isDate1BeforeDate2(Calendar date1, Calendar date2) {
        if (setDayFormat(date1).before(setDayFormat(date2))) {
            return true;
        }
        return false;
    }
}
